# datetime : 12/9/2024 下午9:51
# -*-coding : utf-8 -*-
# Author : 油条测试

'''
读取exl数据
'''
import xlrd2
from openpyxl import load_workbook


# import sys
# sys.path.append('../data/config_data.py')
# from data.config_data import Config_col
# # from data.config_data import Config_col

class Operate_Excel:
    def __init__(self, filePath=None, fileName=None):
        if fileName != None and filePath != None:
            self.filePath = filePath
            self.fileName = fileName
        else:
            self.filePath = '../data_config/interface.xlsx'
            self.fileName = 'Sheet1'

    # self.col = Config_col()
    # 打开表格
    def readExcels(self):
        book = xlrd2.open_workbook(self.filePath)
        table = book.sheet_by_name(self.fileName)
        return table

    # 获取行数
    def get_rows(self):
        return self.readExcels().nrows

    # 获取表格的指定内容
    def read_cell_values(self, row, col):
        return self.readExcels().cell_value(row, col)

    # 写入数据到exl表格
    def input_value(self, row, col, value):
        # 打开表格
        wb = load_workbook(self.filePath)
        # 读取sheet对象
        sheet = wb[self.fileName]
        # 写入数据到exl
        sheet.cell(row + 1, col + 1, value)
        # 关闭exl
        wb.save(self.filePath)
